package com.genesis.web.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.genesis.mall.common.OmsOrderReturnPage;
import com.genesis.mall.common.Result;
import com.genesis.mall.entity.OmsOrderReturnReason;
import com.genesis.mall.service.IOmsOrderReturnReasonService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 退货原因表 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-08-01
 */
//TODO 前后台冲突
//@RestController
//@RequestMapping("/returnReason")
public class OmsOrderReturnReasonController {

    @Autowired
    private IOmsOrderReturnReasonService omsOrderReturnReasonService;

    @GetMapping("/list")
    public Result<OmsOrderReturnPage<OmsOrderReturnReason>>list(Long pageNum,Long pageSize){
        Page<OmsOrderReturnReason> pageInfo = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<OmsOrderReturnReason> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(OmsOrderReturnReason::getCreateTime);

        omsOrderReturnReasonService.page(pageInfo,wrapper);
        OmsOrderReturnPage<OmsOrderReturnReason> page = new OmsOrderReturnPage<>();

        BeanUtils.copyProperties(pageInfo,page);

        return Result.success(page);

    }

    @GetMapping("{id}")
    public Result<OmsOrderReturnReason>getById(@PathVariable Long id){
        OmsOrderReturnReason returnReason = omsOrderReturnReasonService.getById(id);
        return Result.success(returnReason);
    }
}
